const mongoose = require('mongoose')

const { dbUrl } = require('../config/config.default')
mongoose.connect(dbUrl, { useNewUrlParser: true, useUnifiedTopology: true });
console.log()
//当连接失败的
const db = mongoose.connection
db.on('error', err => {
  console.log('err', err)
}
)
//连接成功
db.once('open', function () {
  console.log('数据库连接成功')
  // we're connected!
})

// 组织导出模型
module.exports = {
  User: mongoose.model('User', require('./user')),
  Article: mongoose.model('Article', require('./article'))
}

